package cn.edu.ujn.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.edu.ujn.common.annotation.Log;
import cn.edu.ujn.common.enums.BusinessType;
import cn.edu.ujn.system.domain.FAdmin;
import cn.edu.ujn.system.service.IFAdminService;
import cn.edu.ujn.common.core.controller.BaseController;
import cn.edu.ujn.common.core.domain.AjaxResult;
import cn.edu.ujn.common.utils.poi.ExcelUtil;
import cn.edu.ujn.common.core.page.TableDataInfo;

/**
 * 管理员信息管理Controller
 * 
 * @author ruoyi
 * @date 2023-11-22
 */
@Controller
@RequestMapping("/system/admin")
public class FAdminController extends BaseController
{
    private String prefix = "system/admin";

    @Autowired
    private IFAdminService fAdminService;

    @RequiresPermissions("system:admin:view")
    @GetMapping()
    public String admin()
    {
        return prefix + "/admin";
    }

    /**
     * 查询管理员信息管理列表
     */
    @RequiresPermissions("system:admin:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FAdmin fAdmin)
    {
        startPage();
        List<FAdmin> list = fAdminService.selectFAdminList(fAdmin);
        return getDataTable(list);
    }

    /**
     * 导出管理员信息管理列表
     */
    @RequiresPermissions("system:admin:export")
    @Log(title = "管理员信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FAdmin fAdmin)
    {
        List<FAdmin> list = fAdminService.selectFAdminList(fAdmin);
        ExcelUtil<FAdmin> util = new ExcelUtil<FAdmin>(FAdmin.class);
        return util.exportExcel(list, "管理员信息管理数据");
    }

    /**
     * 新增管理员信息管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存管理员信息管理
     */
    @RequiresPermissions("system:admin:add")
    @Log(title = "管理员信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FAdmin fAdmin)
    {
        return toAjax(fAdminService.insertFAdmin(fAdmin));
    }

    /**
     * 修改管理员信息管理
     */
    @RequiresPermissions("system:admin:edit")
    @GetMapping("/edit/{adminId}")
    public String edit(@PathVariable("adminId") Long adminId, ModelMap mmap)
    {
        FAdmin fAdmin = fAdminService.selectFAdminByAdminId(adminId);
        mmap.put("fAdmin", fAdmin);
        return prefix + "/edit";
    }

    /**
     * 修改保存管理员信息管理
     */
    @RequiresPermissions("system:admin:edit")
    @Log(title = "管理员信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FAdmin fAdmin)
    {
        return toAjax(fAdminService.updateFAdmin(fAdmin));
    }

    /**
     * 删除管理员信息管理
     */
    @RequiresPermissions("system:admin:remove")
    @Log(title = "管理员信息管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fAdminService.deleteFAdminByAdminIds(ids));
    }
}
